<?php

namespace App\Models;

use App\Enums\BookStatus;
use App\Enums\OrderStatus;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Str;

class Order extends Model
{
    use HasFactory;

    protected $casts = [
        'status' => OrderStatus::class,
    ];
    protected static function boot()
    {
        parent::boot();

        static::creating(function ($order) {
            $order->sn = static::generateOrderNumber();
        });
    }

    protected static function generateOrderNumber(): string
    {
        return Str::uuid()->toString();
    }

    public function book(): BelongsTo
    {
        return $this->belongsTo(Book::class,'book_id');
    }
    public function user(): BelongsTo
    {
        return $this->belongsTo(Member::class,'user_id');
    }
    public function category(): BelongsTo
    {
        return $this->belongsTo(Category::class,'category_id');
    }
}
